package com.plian.system.controller.sys.file;

import com.plian.Tools.FileTools;
import com.plian.system.service.sys.file.TemplateDemoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;

@RestController
@RequestMapping(value = "api/templateDemo")
public class TemplateDemoController {

    @Autowired
    private TemplateDemoService templateDemoService;

    @GetMapping("/exportTemplateExcel/{type}")
    @ApiOperation(value = "excel模板文件下载", notes = "模板文件下载")
    public void exportTemplateExcel(HttpServletResponse response, OutputStream os, @PathVariable String type){
        templateDemoService.exportTemplateExcel(response, os, type);
    }

    @GetMapping("/buildpdf/{type}")
    @ApiOperation(value = "pdf文件下载", notes = "pdf文件下载")
    public ResponseEntity<FileSystemResource> buildPdf(HttpServletResponse response,@PathVariable String type) {
        return FileTools.exportPdf(templateDemoService.buildpdf(response, type));
    }

}
